package org.flower.web.servlet;

import org.flower.bean.Order;
import org.flower.entity.User;
import org.flower.service.OrderService;
import org.flower.service.impl.OrderServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(value = "/user/orderServlet.shtml")
public class OrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        OrderService orderService = new OrderServiceImpl();
        //获取作用域中的用户id
        User user = (User)request.getSession().getAttribute("user");
        //获取页面状态值
        String  zt=request.getParameter("zt");
        int num;
        int sum=-1;
        if(zt==null||zt.equals("")){
            zt="0";
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNum",num);
            sum=num;
        }else if(zt.equals("1")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumDai",num);
            sum=num;
        }else if(zt.equals("2")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumJIn",num);
            sum=num;
        }else if(zt.equals("3")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumDaiPingJia",num);
            sum=num;
        }else if(zt.equals("4")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumYiWanCheng",num);
            sum=num;
        }else if(zt.equals("5")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumYiQuXiao",num);
            sum=num;
        }else if(zt.equals("6")){
            num = orderService.getNum(user.getId(),Integer.parseInt(zt));
            request.getSession().setAttribute("orderNumJinRi",num);
            sum=num;
        }

        request.setAttribute("zts",zt);
        request.setAttribute("sum",sum);

        List<Order> orderList = orderService.getById(user.getId(),zt);

        request.getSession().setAttribute("orderList",orderList);
        request.getRequestDispatcher("../order.jsp").forward(request,response);
    }
}
